<template>
	<!-- v-if判断是否真的登录了 -->
	<view class="userLayout pageBg">
		<view :style="{height:getNavBarHeight()+'px'}"></view>
		<view class="userInfo">
			<!-- 展示用户头像 -->
			<view class="avatar">
				<!-- 修改：图标，从后端获取 -->
				<image :src="`${BASE_URL}${userinfo.avatarUrl}`" mode="aspectFill"></image>
			</view>
			<!-- 修改：展示用户的名字 -->
			<view class="name">{{userinfo.username}}</view>
<!-- 			<view class="ip">{{userinfo.IP}}</view>
			<view class="address">来自于：
				{{ (userinfo.address.country ? userinfo.address.country : '') +
					(userinfo.address.province ? ' | ' + userinfo.address.province : '') +
					(userinfo.address.city ? ' | ' + userinfo.address.city : '') }}
			</view> -->
		</view>
		<!-- 在这里加我的收藏 -->
		<view class="collection">
			<navigator
			url="/pages/book/bookcollection" 
			class="row">
				<view class="left">
					<uni-icons type="star-filled" size="20"></uni-icons>
					<view class="text">我的收藏</view>
					<uni-icons class="right" type="arrow-right" size="20"></uni-icons>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script setup>
import { getNavBarHeight } from "@/utils/system.js"
import { apiUserInfo } from "@/api/apis.js"
import { ref } from "vue";
import { BASE_URL } from "../../utils/request";
import { onLoad } from "@dcloudio/uni-app";

const userinfo = ref({});

onLoad((e) => {
  getUserInfo();
});

const getUserInfo = async () => {
	const res = await apiUserInfo();
	userinfo.value = res.data;
};

</script>

<style lang="scss" scoped>
.userLayout {
	.userInfo {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding: 50rpx 0;
		.avatar {
			width: 160rpx;
			height: 160rpx;
			border-radius: 50%;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
		.ip {
			font-size: 44rpx;
			color: #333;
			padding: 20rpx 0 5rpx;
		}
		.address {
			font-size: 28rpx;
			color: #aaa;
		}
	}
	.collection {
		width: 100%;
		margin-top: 50rpx;
		background-color: #fff;
		border-radius: 20rpx;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.3);
		.row {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			border-bottom: 1rpx solid #eee;
			&:last-child {
				border-bottom: none;
			}
			.left {
				display: flex;
				align-items: center;
				.text {
					margin: 12rpx;
					font-size: 32rpx;
					color: #333;
				}
			}
			.right {
				margin-left: 250px;
				color: #999;
			}
		}
	}
}
</style>
